/* ** por compatibilidad se omiten tildes **
================================================================================
 TRABAJO PRACTICO 3 - System Programming - ORGANIZACION DE COMPUTADOR II - FCEN
================================================================================
  definicion de funciones del manejador de memoria
*/

#ifndef __MMU_H__
#define __MMU_H__

#include "defines.h"
#include "i386.h"
#include "tss.h"
#include "game.h"

#define MAX_ENTRY 1024			    //cantidad de entradas de la tablas.

typedef struct str_page_dir_entry { 	//el directorio de paginas 
    unsigned char   p:1; 
    unsigned char   rw:1;
    unsigned char   us:1;
    unsigned char   pwt:1;
    unsigned char   pcd:1;
    unsigned char   a:1;
    unsigned char   i:1;
    unsigned char   ps:1;
    unsigned char   g:1;
    unsigned char   disponible:3;
    unsigned int    dir_base:20;
} __attribute__((__packed__, aligned (4))) page_dir_entry;


typedef struct str_page_table_entry{  	//tabla de paginas
    unsigned char   p:1;
    unsigned char   rw:1;
    unsigned char   us:1;
    unsigned char   pwt:1;
    unsigned char   pcd:1;
    unsigned char   a:1;
    unsigned char   d:1;
    unsigned char   pat:1;
    unsigned char   g:1;
    unsigned char   disponible:3;
    unsigned int    dir_base_p:20;
}__attribute__((__packed__,aligned(4))) page_table_entry;

void mmu_inicializar();
void mmu_mapear_pagina(unsigned int virtual, unsigned int cr3, unsigned int fisica, unsigned char priv_level);
page_dir_entry* mmu_inicializar_dir_kernel(void);
void mmu_unmapear_pagina(unsigned int virtual, unsigned int cr3);
void mmu_mapear_pagina(unsigned int virtual, unsigned int cr3, unsigned int fisica, unsigned char priv_level);
void* ubicacion(unsigned int i, unsigned int j);
page_dir_entry* mmu_inicializar_dir_zombi(char jugador, unsigned int pos_i, char z_type);
void mmu_mapear_cuadrado(unsigned int i, unsigned int j, unsigned int pd, char jugador);
void* dame_pagina_libre();
void cpy_code(char* dst, char* src, unsigned int tam);

#endif	/* !__MMU_H__ */




